************This do file gathers all the necessary variable needed to estimate the impact of the war on drugs in growth for States in Mexico***********

************This do file gathers all the necessary variable needed to estimate the impact of the war on drugs in growth for States in Mexico***********

clear
set more off
set mem 2000m
local pathdata "C:\Users\jose.balmori\Universidad Anahuac Dropbox\Jose Balmori\Paper 47 e-crime\Data\Final"
cd "`pathdata'"
 

*cd   "C:\Users\Lauren Velasco\Dropbox\1.3 Research\general_mex\Paper 28 Accidents\analysis\data\"
use Base.dta, clear

local pathdata2 "C:\Users\jose.balmori\Universidad Anahuac Dropbox\Jose Balmori\Paper 47 e-crime\Paper Oct 23\output"
cd "`pathdata2'"
rename ano yr

drop if yr == 2015 | yr == 2016


 * S1 Generate variable COVID
 gen Treatment=yr>2020
 gen Post=mes>=3 & mes<=12
 gen COVID=Treatment*Post
 replace COVID=1 if (yr==2020 & mes>=3) |   yr>2020 /*Change to 2020 */
 tab COVID
 tab mes yr if COVID==1
 label var COVID "1(COVID-19)" 
 
  g Robberyt = RoboAutopartesCont + RoboTrasnportistaCont + RoboTranseunteVPCont + RoboTranseunteEACont + RoboTransportePubIndCont  /*
 */+ RoboTransportePubColCont + RoboTransporteIndividualCont + RoboBancoCont + RoboNegocioCont + RoboGanadoCont + RoboMaquinariaCont + RoboOtroCont
 g Theftt = RoboAutopartesSint + RoboTrasnportistaSint + RoboTranseunteVPSint + RoboTranseunteEASint + RoboTransportePubIndSint + RoboTransportePubColSint /*
 */ + RoboTransporteIndividualSint + RoboBancoSint + RoboNegocioSint + RoboGanadoSint + RoboMaquinariaSint + RoboOtroSint
 g Propertyt = DanoPropt+ Despojot
 
 label var Fraudet "Fraud"
 label var Robberyt "Robbery"
 label var Theftt "Theft"
 label var RoboCasat "Domestic Burglary"
 label var RoboVeht "Motor Vehicle Theft"
 label var Extorsiont "Extortion"
 label var AbusoConft "Embezzlement"
 label var Propertyt "Vandilism"
 
********************************
* Table 1:  Summary Statistics 
********************************  
	 eststo clear
	 local x Fraudet Robberyt Theftt RoboCasat RoboVeht
	/*
	 gen no_after=Post==0
	 eststo controlpre: estpost sum `sum' if  Post==0 & Treatment==0 
	 eststo controlpost: estpost sum `sum' if  Post==1 & Treatment==0 
	 eststo diffcontrol:  estpost  ttest   `sum' if Treatment==0 , by(no_after) unequal
	 
	 eststo treatmentpre: estpost sum `sum' if  Post==0 & Treatment==1
	 eststo treatmentpost: estpost sum `sum' if  Post==1 & Treatment==1 
		eststo difftreat:  estpost  ttest   `sum' if Treatment==1 , by(no_after) unequal
	 */
	 foreach var in  COVID  {
		 eststo post`var': estpost sum `x' if `var'==1 [aw=pob]
		 eststo pre`var': estpost sum `x' if `var'==0 [aw=pob]
	*	 eststo diff`var':  estpost  ttest   `x' , by(no_`var') unequal
		 *estadd matrix diff_pct`var'  = (r(diff`var') / r(mu_2) * 100)
	 } 
	  * sd(pattern(1 1 0 1 1 0) fmt(%9.2fc) label(Std. Dev.)) 
	  /*
		foreach y in  x  {
		sum `y' if COVID==1
		g postCOVID_mean_`y' = r(mean)
		sum `y' if COVID==1
		g preCOVID_mean_`y' = r(mean)
	    gen diff_pctCOVID_`y' = (postCOVID_mean_`y' - preCOVID_mean_`y') / preCOVID_mean_`y' * 100
		}

	esttab  preCOVID postCOVID diffCOVID  diff_pctCOVID  using"${output}SS.tex", replace /*
	*/ cells("mean(pattern(1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 )  fmt(%9.2fc) label(Mean)) sd(pattern(1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 )  fmt(%9.2fc) label(Std. Dev.)) b( star  pattern(0 0 1 0 0 0 0 1 0 0 1 0 0 1) fmt(%9.2fc) label(Diff.)) diff_pctCOVID(pattern(0 0 0 0 0 0 0 0 0 0 0 0 0 0 1) fmt(%9.2f) label(Diff. %))")  /*
	*/ star(* 0.10 ** 0.05 *** 0.01)  ///
				mtitles(  "\shortstack{Pre-\\COVID}" "\shortstack{Post-\\COVID}" "\shortstack{Pre-Post\\Pandemic}"  ) ///
				mgroups( "\large \textbf{Pre-Post-Pandemic}"  ///
							, pattern(1 0 0 1 0 1 0 0 1 0 0 1 0 0 0) /// 
				prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))  ///
				stats( N , labels( "`N'" ) fmt(%9.0fc)) label nonumber booktabs    
	  */
	  
	  	esttab  preCOVID postCOVID using"${output}SS.tex", replace /*
	*/ cells("mean(pattern(1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 )  fmt(%9.2fc) label(Mean)) sd(pattern(1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 )  fmt(%9.2fc) label(Std. Dev.)) b( star  pattern(0 0 1 0 0 0 0 1 0 0 1 0 0 1) fmt(%9.2fc) label(Diff.))")  /*
	*/ star(* 0.10 ** 0.05 *** 0.01)  ///
				mtitles(  "\shortstack{Pre-\\COVID}" "\shortstack{During-\\COVID}" "\shortstack{Pre-Dur\\Pandemic}"  ) ///
				mgroups( "\large \textbf{Pre-Post-Pandemic}"  ///
							, pattern(1 0 0 1 0 1 0 0 1 0 0 1 0 0 0) /// 
				prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))  ///
				stats( N , labels( "`N'" ) fmt(%9.0fc)) label nonumber booktabs    
	  clear all
